﻿using System;
using System.Data;
using visinia.SmartEngine.Providers;

namespace viForum.Providers
{
    public abstract partial class viForumDataProvider
    {
        #region INIT
        private static viForumDataProvider _provider;
        private static object _lock = new object();

        public static viForumDataProvider Provider
        {
            get { InternalInitialize(); return _provider; }
        }
        private static void InternalInitialize()
        {
            if (_provider == null)
            {
                lock (_lock)
                {
                    if (_provider == null)
                    {
                        _provider = (viForumDataProvider)ProviderController.CreateDataProvider("viForum");
                        if (_provider == null)
                            throw new Exception("Unable to load default viForumDataProvider");
                    }
                }
            }
        }
        #endregion

        #region FORUM
        public abstract void AddForum(int CategoryId, string Title, string Description);
        public abstract void UpdateForum(int ForumId, int CategoryId, string Title, string Description);
        public abstract void DeleteForum(int ForumId);
        public abstract IDataReader GetForums();
        public abstract IDataReader GetPostCount(int ForumId);
        #endregion

        #region THREAD
        public abstract IDataReader AddThread(int ForumId, string UserName, string Title, DateTime Date, string Content);
        public abstract void UpdateThread(int ThreadId, int ForumId, string UserName, string Title, DateTime Date, string Content);
        public abstract void DeleteThread(int ThreadId);
        public abstract IDataReader GetThreads(int ForumId);
        public abstract IDataReader GetThread(int ThreadId);
        public abstract IDataReader GetThreadCount(int ForumId);
        public abstract IDataReader GetLatestThread(int ForumId);
        public abstract IDataReader GetLatestThreads(int Count);
        #endregion

        #region REPLY
        public abstract IDataReader AddReply(int ThreadId, string UserName, DateTime Date, string Content);
        public abstract void UpdateReply(int ReplyId, int ThreadId, string UserName, DateTime Date, string Content);
        public abstract void DeleteReply(int ReplyId);
        public abstract IDataReader GetReplies(int ThreadId);
        public abstract IDataReader GetReply(int ReplyId);
        public abstract IDataReader GetRepliesCount(int ThreadId);
        public abstract IDataReader GetLatestReply(int ThreadId);
        #endregion

        #region FORUM SETTINGS
        public abstract IDataReader GetForumSettings();
        public abstract void AddForumSetting(string key, string value);
        public abstract void UpdateForumSetting(string key, string value);
        public abstract void DeleteForumSetting(string key);
        #endregion

        #region CATEGORY
        public abstract void AddCategory(string Title);
        public abstract void UpdateCategory(int CategoryId, string Title);
        public abstract void DeleteCategory(int CategoryId);
        public abstract IDataReader GetCategories();
        #endregion

        #region USER
        public abstract void AddUser(string UserName, int PostsCount);
        public abstract void DeleteUser(string UserName);
        public abstract void UpdateUser(string UserName, int PostsCount);
        public abstract IDataReader GetUser(string UserName);
        #endregion
    }
}
